// fn/delay
// 节流有一个节流阀， 防抖是来了就重置
// setTimeout 就是一个没有输入回调函数
function debounce(func, delay) {
  let timer = null
  return (...args) => {
    timer = setTimeout(() => {
      func.apply(this, args)
    }, delay)
  }
}
// 不用闭包的实现，也是ok的但是有可能会污染全局变量！
// 因为链式作用域所以闭包的优先级是高于上一层的timer的，从而实现如果timer存在就清空重来的效果

function debounce(fn, delay) {
  let timer = null
  return function () {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(fn, delay)
  }
}
// 传统写法
function debounce(fn, delay) {
  let timer = null
  return function () {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(fn, arguments)
  }
}

// fn如果有参数的话需要让参数指向fn ES6写法
function debounce(fn, delay) {
  let timer = null
  return (...args) => {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      fn.apply(this, args)
    }, delay)
  }
}

const debounce(fn,delay) {
  let timer = null
  return (...args) => {
    if(timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(()=> {
      fn.apply(this,args)
    },delay)
  }
}
// 传统写法
function debounce(fn, delay) {
  let timer = null
  return function () {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(fn, arguments)
  }
}

function deboucne(fn,delay) {
  let timer = null
  return function () {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(fn,arguments)
  }
}
// 防抖只是去判断timer！！
function debounce(fn,delay) {
  let timer = null
  return function () {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(fn,arguments)
  }
}
// 伪数组到数组
// Array.from()
// [].slice.call()
apply(this,arguments)